import { createRouter, createWebHashHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const routes = [
  {
    path: '/',
    name: '主页',
    component: () => import('../layout/index.vue'),
    meta: {
           title: 'cmdb',
           isAuthRequired:true
         },
    redirect:'/index',
    children:[
      {
        path: '/index',
        name: '首页',
        component: () => import('../views/index/index.vue'),
        meta: {
           isAuthRequired:true
        },
      },
      {
        path: '/sys/user',
        name: '用户管理',
        component: () => import('../views/sys/user/index.vue'),
        meta: {
             isAuthRequired:true
         },
      },
      {
        path: '/sys/role',
        name: '角色管理',
        component: () => import('../views/sys/role/index.vue'),
        meta: {
             isAuthRequired:true
         },
      },
      {
        path: '/sys/menu',
        name: '菜单管理',
        component: () => import('../views/sys/menu/index.vue'),
        meta: {
             isAuthRequired:true
         },
      },
      {
        path: '/bsns/department',
        name: '部门管理',
        component: () => import('../views/bsns/Department'),
        meta: {
             isAuthRequired:true
         },
      },
      {
        path: '/bsns/post',
        name: '岗位管理',
        component: () => import('../views/bsns/Post'),
        meta: {
             isAuthRequired:true
         },
      },
       {
        path: '/userCenter',
        name: '个人中心',
        component: () => import('../views/userCenter/index'),
        meta: {
             isAuthRequired:true
         },
      },
       {
        path: '/bsns/ansible',
        name: 'ansible部署',
        component: () => import('../views/bsns/Post'),
        meta: {
             isAuthRequired:true
         },
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/Login.vue'),
    meta: {
           title: 'login',
    },
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})


import store from "../store"
router.beforeEach((to,from)=>{
  document.title = to.meta.title;
  if(to.name) {
    to.name = to.name.trim().replace(/[\r\n]/g, '')
  }
  return true
  if (to.meta.isAuthRequired == true && store.state.user.isLogin == false)
      router.push('/login')
  })
export default router


